package sg.edu.ntu.bloch.tictactoe.engine;

import java.security.InvalidParameterException;

public class Player {

	private String player;

	public Player(String player) {
		this.setPlayer(player);
	}

	public void setPlayer(String player) {
		if (player == null || player.trim().isEmpty())
			throw new InvalidParameterException(
					"Player name should not be null or empty String");
		this.player = player.trim();
	}

	public String getPlayer() {
		assert this.player != null;
		return player;
	}
	
	@Override
	public String toString() {
		return "Player [player=" + player + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((player == null) ? 0 : player.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Player other = (Player) obj;
		if (player == null) {
			if (other.player != null)
				return false;
		} else if (!player.equals(other.player))
			return false;
		return true;
	}
}